package cn.yzgy.yzgyoa.common.controller;


import cn.yzgy.yzgyoa.common.annotation.ApiDesc;
import cn.yzgy.yzgyoa.common.annotation.Syslog;
import cn.yzgy.yzgyoa.common.crsp.Urmf;
import cn.yzgy.yzgyoa.common.dto.SysFileInfoDto;
import cn.yzgy.yzgyoa.common.entity.SysFileInfo;
import cn.yzgy.yzgyoa.common.service.ISysFileInfoService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Yqsen
 * @since 2021-11-03
 */
@Slf4j
@Syslog
@RestController
@RequestMapping("/common/sys-file-info")
public class SysFileInfoController extends BaseController {

    private ISysFileInfoService sysFileInfoService;

    public SysFileInfoController(ISysFileInfoService sysFileInfoService) {
        this.sysFileInfoService = sysFileInfoService;
    }

    @ApiDesc("文件列表")
    @GetMapping("/getAllFiles")
    @RequiresPermissions("api:common:file:getAllFiles")
    public Urmf getAllFiles(@RequestParam Integer page, @RequestParam Integer size, SysFileInfoDto queryDto) {
        IPage<SysFileInfoDto> dictPage = sysFileInfoService.getAllFiles(new Page<>(page, size), queryDto);
        return Urmf.success(getCurrentMethodName(), dictPage);
    }

    @ApiDesc("删除文件")
    @RequiresPermissions("api:common:file:delFiles")
    @DeleteMapping("/delFiles")
    @ResponseBody
    public Urmf delFiles(@RequestBody SysFileInfo sysFileInfo) {
        boolean state = sysFileInfoService.delFile(sysFileInfo);
        if(!state){
            return Urmf.fail(getCurrentMethodName(), "文件删除失败");
        }
        return Urmf.success(getCurrentMethodName(), "文件删除成功");
    }

}
